﻿using System;
using UnityEngine;

// Token: 0x0200013B RID: 315
[RequireComponent(typeof(VehicleParent))]
[DisallowMultipleComponent]
[AddComponentMenu("RVP/C#/Effects/Light Controller", 2)]
public class LightController : MonoBehaviour
{
	// Token: 0x060005BE RID: 1470 RVA: 0x0002D990 File Offset: 0x0002BB90
	private void Start()
	{
		this.vp = base.GetComponent<VehicleParent>();
		if (this.transmission)
		{
			if (this.transmission is GearboxTransmission)
			{
				this.gearTrans = (this.transmission as GearboxTransmission);
			}
			else if (this.transmission is ContinuousTransmission)
			{
				this.conTrans = (this.transmission as ContinuousTransmission);
			}
		}
	}

	// Token: 0x060005BF RID: 1471 RVA: 0x0002DA00 File Offset: 0x0002BC00
	private void Update()
	{
		if (this.leftBlinkersOn || this.rightBlinkersOn)
		{
			if (this.blinkerSwitchTime == 0f)
			{
				this.blinkerIntervalOn = !this.blinkerIntervalOn;
				this.blinkerSwitchTime = this.blinkerInterval;
			}
			else
			{
				this.blinkerSwitchTime = Mathf.Max(0f, this.blinkerSwitchTime - Time.deltaTime);
			}
		}
		else
		{
			this.blinkerIntervalOn = false;
			this.blinkerSwitchTime = 0f;
		}
		if (this.gearTrans)
		{
			this.reverseLightsOn = (this.gearTrans.curGearRatio < 0f);
		}
		else if (this.conTrans)
		{
			this.reverseLightsOn = this.conTrans.reversing;
		}
		if (this.vp.accelAxisIsBrake)
		{
			this.brakelightsOn = (this.vp.accelInput != 0f && Mathf.Sign(this.vp.accelInput) != Mathf.Sign(this.vp.localVelocity.z) && Mathf.Abs(this.vp.localVelocity.z) > 1f);
		}
		else if (!this.vp.brakeIsReverse)
		{
			this.brakelightsOn = ((this.vp.burnout > 0f && this.vp.brakeInput > 0f) || this.vp.brakeInput > 0f);
		}
		else
		{
			this.brakelightsOn = ((this.vp.burnout > 0f && this.vp.brakeInput > 0f) || (this.vp.brakeInput > 0f && this.vp.localVelocity.z > 1f) || (this.vp.accelInput > 0f && this.vp.localVelocity.z < -1f));
		}
		this.SetLights(this.headlights, this.highBeams, this.headlightsOn);
		this.SetLights(this.brakeLights, this.headlightsOn || this.highBeams, this.brakelightsOn);
		this.SetLights(this.RightBlinkers, this.rightBlinkersOn && this.blinkerIntervalOn);
		this.SetLights(this.LeftBlinkers, this.leftBlinkersOn && this.blinkerIntervalOn);
		this.SetLights(this.ReverseLights, this.reverseLightsOn);
	}

	// Token: 0x060005C0 RID: 1472 RVA: 0x0002DCCC File Offset: 0x0002BECC
	private void SetLights(VehicleLight[] lights, bool condition)
	{
		foreach (VehicleLight vehicleLight in lights)
		{
			vehicleLight.on = condition;
		}
	}

	// Token: 0x060005C1 RID: 1473 RVA: 0x0002DCFC File Offset: 0x0002BEFC
	private void SetLights(VehicleLight[] lights, bool condition, bool halfCondition)
	{
		foreach (VehicleLight vehicleLight in lights)
		{
			vehicleLight.on = condition;
			vehicleLight.halfOn = halfCondition;
		}
	}

	// Token: 0x04000852 RID: 2130
	private VehicleParent vp;

	// Token: 0x04000853 RID: 2131
	public bool headlightsOn;

	// Token: 0x04000854 RID: 2132
	public bool highBeams;

	// Token: 0x04000855 RID: 2133
	public bool brakelightsOn;

	// Token: 0x04000856 RID: 2134
	public bool rightBlinkersOn;

	// Token: 0x04000857 RID: 2135
	public bool leftBlinkersOn;

	// Token: 0x04000858 RID: 2136
	public float blinkerInterval = 0.3f;

	// Token: 0x04000859 RID: 2137
	private bool blinkerIntervalOn;

	// Token: 0x0400085A RID: 2138
	private float blinkerSwitchTime;

	// Token: 0x0400085B RID: 2139
	public bool reverseLightsOn;

	// Token: 0x0400085C RID: 2140
	public Transmission transmission;

	// Token: 0x0400085D RID: 2141
	private GearboxTransmission gearTrans;

	// Token: 0x0400085E RID: 2142
	private ContinuousTransmission conTrans;

	// Token: 0x0400085F RID: 2143
	public VehicleLight[] headlights;

	// Token: 0x04000860 RID: 2144
	public VehicleLight[] brakeLights;

	// Token: 0x04000861 RID: 2145
	public VehicleLight[] RightBlinkers;

	// Token: 0x04000862 RID: 2146
	public VehicleLight[] LeftBlinkers;

	// Token: 0x04000863 RID: 2147
	public VehicleLight[] ReverseLights;
}
